import React, { Component } from 'react'
import PropTypes from 'prop-types'
import HighComponent from './Hoc'
import getDefaultOption from '../GenOptions'

class Gdu extends Component {
  componentDidMount() {
    this.update()
  }
  componentDidUpdate() {
    this.update()
  }
  update = () => {
    const { echart, unit } = this.props
    const { result: { dates, gdu, gduDegree } } = this.props
    echart.setOption(
      getDefaultOption(unit ? '历年GDU(°C)' : '历年GDU(°F)', {}, dates, {
        name: 'GDU',
        itemStyle: {
          normal: {
            color: '#228B22',
            lineStyle: {
              width: 1,
              color: '#228B22',
            },
            
          }
        },
        data: unit ? gduDegree : gdu,
        //.map(temp => (temp))
        //.map(temp => unit ? ((temp - 32) / 1.8) : (temp)),
        type: 'line'
      }, function (value) {
        return value
      })
    )
  }
 
 
  render() {
    return (
      null
    )
  }
}

Gdu.propTypes = {
  result: PropTypes.object,
  echart: PropTypes.object,
  unit: PropTypes.bool,
}

export default HighComponent(Gdu, 'gdu')